<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;

class Truncte extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'tables:truncate';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '清空数据库数据';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $tables = DB::select('show tables');
        $tables = array_column($tables, 'Tables_in_kanglv');
        foreach ($tables as $table) {
            if (in_array($table, ['admin', 'banner', 'banner2', 'com_rules', 'commodity', 'day_tasks', 'dic_commons', 'permission_role', 'permissions', 'role_user', 'roles', 's_shangpin', ])) {
                continue;
            }
            DB::statement("TRUNCATE $table");
        }
    }
}
